package top.xana.acg.common.view

import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ItemDecoration


/**
 * Created by xana on 2022/1/9
 * Describe: hello world
 */
class SpacesItemDecoration(space: Int) : ItemDecoration() {
    private val space: Int
    override fun getItemOffsets(
        outRect: Rect, view: View,
        parent: RecyclerView, state: RecyclerView.State
    ) {
        outRect.left = space
        outRect.right = space
        outRect.bottom = space

        // Add top margin only for the first item to avoid double space between items
        if (parent.getChildPosition(view) == 0) outRect.top = space
    }

    init {
        this.space = space
    }
}